servo3 2.2.0
Loading...
Searching...
No Matches
servo3.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef SERVO3_H
29#define SERVO3_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_pwm.h"
52
58
63
68
78#define SERVO3_PWM_MAX 4095
79#define SERVO3_PWM_MIN 0
80#define SERVO3_PWM_ZERO_DEGREE_PULSE 3969
81#define SERVO3_PWM_180_DEGREE_PULSE 3461
82
87#define SERVO3_FC_PS_MODE_DISABLED 0x000000ul
88#define SERVO3_FC_PS_MODE_ENABLED 0x038000ul
89#define SERVO3_FC_PS_MODE_MASK 0x038000ul
90#define SERVO3_FC_OLDENA_DISABLED 0x000000ul
91#define SERVO3_FC_OLDENA_ENABLED 0x004000ul
92#define SERVO3_FC_OLDENA_MASK 0x004000ul
93#define SERVO3_FC_IDMCUR_2_UA 0x000000ul
94#define SERVO3_FC_IDMCUR_10_UA 0x001000ul
95#define SERVO3_FC_IDMCUR_20_UA 0x002000ul
96#define SERVO3_FC_IDMCUR_1_MA 0x003000ul
97#define SERVO3_FC_IDMCUR_MASK 0x003000ul
98#define SERVO3_FC_IDMRPT_NOT_REPEATED 0x000000ul
99#define SERVO3_FC_IDMRPT_REPEATED 0x000800ul
100#define SERVO3_FC_IDMRPT_MASK 0x000800ul
101#define SERVO3_FC_IDMENA_DISABLED 0x000000ul
102#define SERVO3_FC_IDMENA_ENABLED 0x000400ul
103#define SERVO3_FC_IDMENA_MASK 0x000400ul
104#define SERVO3_FC_LATTMG_17TH 0x000000ul
105#define SERVO3_FC_LATTMG_33TH 0x000100ul
106#define SERVO3_FC_LATTMG_65TH 0x000200ul
107#define SERVO3_FC_LATTMG_129TH 0x000300ul
108#define SERVO3_FC_LATTMG_MASK 0x000300ul
109#define SERVO3_FC_LSDVLT_35PCT_VCC 0x000000ul
110#define SERVO3_FC_LSDVLT_45PCT_VCC 0x000040ul
111#define SERVO3_FC_LSDVLT_55PCT_VCC 0x000080ul
112#define SERVO3_FC_LSDVLT_65PCT_VCC 0x0000C0ul
113#define SERVO3_FC_LSDVLT_MASK 0x0000C0ul
114#define SERVO3_FC_LODVLT_0_3_V 0x000000ul
115#define SERVO3_FC_LODVLT_0_6_V 0x000010ul
116#define SERVO3_FC_LODVLT_0_9_V 0x000020ul
117#define SERVO3_FC_LODVLT_1_2_V 0x000030ul
118#define SERVO3_FC_LODVLT_MASK 0x000030ul
119#define SERVO3_FC_ESPWM_DISABLED 0x000000ul
120#define SERVO3_FC_ESPWM_ENABLED 0x000008ul
121#define SERVO3_FC_ESPWM_MASK 0x000008ul
122#define SERVO3_FC_TMGRST_DISABLED 0x000000ul
123#define SERVO3_FC_TMGRST_ENABLED 0x000004ul
124#define SERVO3_FC_TMGRST_MASK 0x000004ul
125#define SERVO3_FC_DSPRPT_DISABLED 0x000000ul
126#define SERVO3_FC_DSPRPT_ENABLED 0x000002ul
127#define SERVO3_FC_DSPRPT_MASK 0x000002ul
128#define SERVO3_FC_BLANK_ON 0x000000ul
129#define SERVO3_FC_BLANK_OFF 0x000001ul
130#define SERVO3_FC_BLANK_MASK 0x000001ul
131#define SERVO3_BC_MIN 0x00
132#define SERVO3_BC_MAX 0x7F
133#define SERVO3_BC_MASK 0x7F
134
139#define SERVO3_ANGLE_MIN 0
140#define SERVO3_ANGLE_MAX 180
141#define SERVO3_CHANNEL_0 0
142#define SERVO3_CHANNEL_1 1
143#define SERVO3_CHANNEL_2 2
144#define SERVO3_CHANNEL_3 3
145#define SERVO3_CHANNEL_4 4
146#define SERVO3_CHANNEL_5 5
147#define SERVO3_CHANNEL_6 6
148#define SERVO3_CHANNEL_7 7
149#define SERVO3_CHANNEL_8 8
150#define SERVO3_CHANNEL_9 9
151#define SERVO3_CHANNEL_10 10
152#define SERVO3_CHANNEL_11 11
153#define SERVO3_CHANNEL_12 12
154#define SERVO3_CHANNEL_13 13
155#define SERVO3_CHANNEL_14 14
156#define SERVO3_CHANNEL_15 15
157#define SERVO3_CHANNEL_ALL 16
158#define SERVO3_NUM_CHANNELS 16
159
164#define SERVO3_DEF_FREQ 256000ul
165#define SERVO3_DEF_DC 0.5
166 // servo3_cfg
168
173
178
183#define SERVO3_MAP_MIKROBUS( cfg, mikrobus ) \
184 cfg.sout = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
185 cfg.sin = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
186 cfg.sclk = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
187 cfg.xlat = MIKROBUS( mikrobus, MIKROBUS_CS ); \
188 cfg.gsclk = MIKROBUS( mikrobus, MIKROBUS_PWM );
189 // servo3_map // servo3
192
197typedef struct
198{
199 // Output pins
200 digital_out_t xlat;
201 digital_out_t sclk;
202 digital_out_t sin;
203
204 // Input pins
205 digital_in_t sout;
206
207 // Modules
208 pwm_t pwm;
209
210 // ctx variable
211 uint32_t pwm_freq;
212
214
215} servo3_t;
216
221typedef struct
222{
223 // Communication gpio pins
224 pin_name_t xlat;
225 pin_name_t sclk;
226 pin_name_t sin;
227 pin_name_t sout;
228 pin_name_t gsclk;
229
230 // Static variable
231 uint32_t dev_pwm_freq;
232
234
239typedef enum
240{
243
245
251
262
276err_t servo3_init ( servo3_t *ctx, servo3_cfg_t *cfg );
277
289err_t servo3_set_duty_cycle ( servo3_t *ctx, float duty_cycle );
290
302
314
326void servo3_write_control ( servo3_t *ctx, uint32_t fc_data, uint8_t bc_data );
327
339void servo3_write_data ( servo3_t *ctx, uint8_t *data_in, uint8_t len );
340
350void servo3_set_sclk_pin ( servo3_t *ctx, uint8_t state );
351
361void servo3_set_sin_pin ( servo3_t *ctx, uint8_t state );
362
372void servo3_set_xlat_pin ( servo3_t *ctx, uint8_t state );
373
383
395err_t servo3_set_channel_pwm ( servo3_t *ctx, uint8_t ch_num, uint16_t pwm_out );
396
408err_t servo3_set_angle ( servo3_t *ctx, uint8_t ch_num, uint8_t angle );
409
419
420#ifdef __cplusplus
421}
422#endif
423#endif // SERVO3_H
424 // servo3
426
427// ------------------------------------------------------------------------ END
#define SERVO3_NUM_CHANNELS
Definition servo3.h:158
err_t servo3_set_channel_pwm(servo3_t *ctx, uint8_t ch_num, uint16_t pwm_out)
Servo 3 set channel PWM function.
uint8_t servo3_get_sout_pin(servo3_t *ctx)
Servo 3 get SOUT pin state function.
err_t servo3_init(servo3_t *ctx, servo3_cfg_t *cfg)
Servo 3 initialization function.
err_t servo3_pwm_start(servo3_t *ctx)
Servo 3 start PWM module.
void servo3_cfg_setup(servo3_cfg_t *cfg)
Servo 3 configuration object setup function.
void servo3_write_data(servo3_t *ctx, uint8_t *data_in, uint8_t len)
Servo 3 write data function.
void servo3_set_sclk_pin(servo3_t *ctx, uint8_t state)
Servo 3 set SCLK pin function.
err_t servo3_pwm_stop(servo3_t *ctx)
Servo 3 stop PWM module.
void servo3_set_xlat_pin(servo3_t *ctx, uint8_t state)
Servo 3 set XLAT pin function.
void servo3_write_control(servo3_t *ctx, uint32_t fc_data, uint8_t bc_data)
Servo 3 write control function.
err_t servo3_set_duty_cycle(servo3_t *ctx, float duty_cycle)
Servo 3 sets PWM duty cycle.
err_t servo3_set_angle(servo3_t *ctx, uint8_t ch_num, uint8_t angle)
Servo 3 set angle function.
void servo3_set_sin_pin(servo3_t *ctx, uint8_t state)
Servo 3 set SIN pin function.
void servo3_update_output(servo3_t *ctx)
Servo 3 update output function.
servo3_return_value_t
Servo 3 Click return value data.
Definition servo3.h:240
@ SERVO3_OK
Definition servo3.h:241
@ SERVO3_ERROR
Definition servo3.h:242
Servo 3 Click configuration object.
Definition servo3.h:222
pin_name_t sclk
Definition servo3.h:225
pin_name_t sin
Definition servo3.h:226
uint32_t dev_pwm_freq
Definition servo3.h:231
pin_name_t sout
Definition servo3.h:227
pin_name_t gsclk
Definition servo3.h:228
pin_name_t xlat
Definition servo3.h:224
Servo 3 Click context object.
Definition servo3.h:198
digital_out_t xlat
Definition servo3.h:200
digital_out_t sin
Definition servo3.h:202
uint16_t pwm_out[SERVO3_NUM_CHANNELS]
Definition servo3.h:213
uint32_t pwm_freq
Definition servo3.h:211
digital_out_t sclk
Definition servo3.h:201
digital_in_t sout
Definition servo3.h:205
pwm_t pwm
Definition servo3.h:208